<?php
$cond = '';
$sort = '';
$ut = $u = $fn = $ln = $dg = 'asc';
if(isset($_GET['sort']))
{
 if($_GET['sort']=='section')
 {
  if($_GET['s_type']=='asc')
  {	$cond=' ORDER BY section ASC';	$sort = '&sort=section&s_type=asc';	$ut='desc';	}
  else
  {	$cond=' ORDER BY section DESC';	$sort = '&sort=section&s_type=desc';	}
 }
  
}
 

?>
			  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Tracking</td>
  </tr>
  <tr>
    <td height="577">
	<table width="100%">
	    <tbody>
		<tr>
		  <td>
		    <form name="frmSearchPro" action="" method="post">
		    <table width="100%" border="0">
		      <tr>
			<td width="30%">Section</td>
			<td width="70%"><input type="text" name="section" id="section" value="<?php echo $_POST['section']; ?>" /></td>
		      </tr>
		      <tr><td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search" /></td></tr>
		    </table>
		    </form>
		  </td>
		</tr>
		<tr>
		  <td>
		    <b>Sort  By :</b>
		    <a href="<?php echo $base_url;?>admin/index.php?tracking&sort=section&s_type=<?php echo $ut;?>">Section</a> &nbsp;&nbsp;&nbsp;
		  </td>
		</tr>
		</tbody>
	</table><br>
	<table width="100%"  border="0" cellspacing="0">      
	  <tr class="InnerHeader">       
	    <td width="15%" class="line">Section </td>
	    <td width="21%" class="line">Daily </td>
	    <td width="21%" class="line">Monthly</td>
	  </tr>
	  
      <?php 
	  $date=date("Y-m-d");				 
				 require_once "../includes/pagination.php";
				 $itemPerPage=15;
				 if(isset($_POST['btnSearchPro'])) {
		      
					$section 	= $_POST['section'];		
				
					if($section!='')
					$search.= "where section='".$section."'";
				 }
				 $sql_shocat="SELECT * FROM tbl_tracking $search  group by section $cond";				 
				 $rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));			
				 $numRows = mysql_num_rows($rst_shocat);
				 if($numRows>0) {
					 while($row_shocat = mysql_fetch_array($rst_shocat)) {	
					 $sqlSection="SELECT count(*) as cnt FROM tbl_tracking where section='".$row_shocat['section']."' and trackdate='".$date."'";
					
					 $resSection=mysql_query($sqlSection);
					 $rowSection=mysql_fetch_array($resSection);	
					 $nrowSection=mysql_num_rows($resSection);			 
					 $sname=$row_shocat['section'];

					 			 
				 ?> 
      <tr>
        <td class="line"><?php echo $sname;?></td>
        <td class="line"><?php echo $rowSection['cnt'];?></td>
        <td class="line"><?php 
					$sqlSectionMonth="SELECT * FROM tbl_tracking where section='".$row_shocat['section']."'";
					
					 $resSectionMonth=mysql_query($sqlSectionMonth);
					 
					echo $nrowSectionMonth=mysql_num_rows($resSectionMonth);			 ;?></td>
      </tr>    <?php } }?>     
       </table>
	<div align="center">
		<?php		   
		   $link="tracking";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link);							   
		?>    
	</div>
	</td>
 </tr>
</table>